package com.project.common.filter;

import lombok.Data;

@Data
public class Criterion {
    private String connective;
    private String column;
    private String operator;
    private Object value;
    private Object nextValue;
    private int type;

    public static Criterion isNull(String column) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.NULL.getValue());
        criterion.setType(Operator.NULL.getId());
        return criterion;
    }

    public static Criterion isSpecialNull(String column) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.NULL.getValue() + ")");
        criterion.setType(Operator.NULL.getId());
        return criterion;
    }

    public static Criterion notNull(String column) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.NOT_NULL.getValue());
        criterion.setType(Operator.NOT_NULL.getId());
        return criterion;
    }

    public static Criterion equal(String column, Object value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.EQUAL.getValue());
        criterion.setValue(value);
        criterion.setType(Operator.EQUAL.getId());
        return criterion;
    }

    public static Criterion notEqual(String column, Object value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.NOT_EQUAL.getValue());
        criterion.setValue(value);
        criterion.setType(Operator.NOT_EQUAL.getId());
        return criterion;
    }

    public static Criterion lessThan(String column, Object value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.LESS_THAN.getValue());
        criterion.setValue(value);
        criterion.setType(Operator.LESS_THAN.getId());
        return criterion;
    }

    public static Criterion lessThanOrEqual(String column, Object value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.LESS_THAN_OR_EQUAL.getValue());
        criterion.setValue(value);
        criterion.setType(Operator.LESS_THAN_OR_EQUAL.getId());
        return criterion;
    }

    public static Criterion greatThan(String column, Object value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.GREAT_THAN.getValue());
        criterion.setValue(value);
        criterion.setType(Operator.GREAT_THAN.getId());
        return criterion;
    }

    public static Criterion greatThanOrEqual(String column, Object value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.GREAT_THAN_OR_EQUAL.getValue());
        criterion.setValue(value);
        criterion.setType(Operator.GREAT_THAN_OR_EQUAL.getId());
        return criterion;
    }

    public static Criterion between(String column, Object value, Object nextValue) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.BETWEEN.getValue());
        criterion.setValue(value);
        criterion.setNextValue(nextValue);
        criterion.setType(Operator.BETWEEN.getId());
        return criterion;
    }

    public static Criterion notBetween(String column, Object value, Object nextValue) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.NOT_BETWEEN.getValue());
        criterion.setValue(value);
        criterion.setNextValue(nextValue);
        criterion.setType(Operator.NOT_BETWEEN.getId());
        return criterion;
    }

    public static Criterion startWith(String column, String value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.START_WITH.getValue());
        criterion.setValue(value + "%");
        criterion.setType(Operator.START_WITH.getId());
        return criterion;
    }

    public static Criterion notStartWith(String column, String value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.NOT_START_WITH.getValue());
        criterion.setValue(value + "%");
        criterion.setType(Operator.NOT_START_WITH.getId());
        return criterion;
    }

    public static Criterion endWith(String column, String value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.END_WITH.getValue());
        criterion.setValue("%" + value);
        criterion.setType(Operator.END_WITH.getId());
        return criterion;
    }

    public static Criterion notEndWith(String column, String value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.NOT_END_WITH.getValue());
        criterion.setValue("%" + value);
        criterion.setType(Operator.NOT_END_WITH.getId());
        return criterion;
    }

    public static Criterion contains(String column, Object value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.CONTAINS.getValue());
        criterion.setValue(value);
        criterion.setType(Operator.CONTAINS.getId());
        return criterion;
    }

    public static Criterion notContains(String column, Object value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.NOT_CONTAINS.getValue());
        criterion.setValue(value);
        criterion.setType(Operator.NOT_CONTAINS.getId());
        return criterion;
    }

    public static Criterion in(String column, Object value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.IN.getValue());
        criterion.setValue(value);
        criterion.setType(Operator.IN.getId());
        return criterion;
    }

    public static Criterion notIn(String column, Object value) {
        Criterion criterion = new Criterion();
        criterion.setColumn(column);
        criterion.setOperator(Operator.NOT_IN.getValue());
        criterion.setValue(value);
        criterion.setType(Operator.NOT_IN.getId());
        return criterion;
    }
}
